<?php
namespace Libraries;
class CNumber{
	public static function format_money($val,$symbol='Rp',$r=2){
		$n=$val;
		$c=is_float($n)?1:number_format($n,$r);
		$d='.';
		$t=',';
		$sign=($n<0)?'-':'';
		$i=$n=number_format(abs($n),$r);
		$j=(($j=strlen($i))>3)?$j%3:0;
		return $symbol.$sign.($j?substr($i,0,$j)+$t:'').preg_replace('/(\d{3})(?=\d)/',"$1"+$t,
				substr($i,$j));
	}
	public static function percent_format($value,$decimal=0){
		return number_format($value*100,$decimal).'%';
	}
	public static function acc_format($value,$decimal=0){
		$normalize=$value<0?-$value:$value;
		$print=number_format($normalize,$decimal);
		return $value<0?"($print)":$print;
	}
}